package com.nnfe.fyd.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.nnfe.fyd.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by dada on 2017/3/21.
 */

public class WebViewFragment extends ActionBarFragment {


    @Bind(R.id.main_webview)
    WebView webview;

    @Override
    public Object getTitleString() {
        String title=getArguments().getString("title");
        return title;
    }

    @Override
    public int getContentView() {
        return R.layout.fragment_webview;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }


    private void initV(){
        String url=getArguments().getString("url");

        WebSettings webSettings = webview.getSettings();
        webSettings.setJavaScriptEnabled(true); // 支持JS操作
        // 设置支持缩放
        webSettings.setSupportZoom(true);
        webSettings.setBuiltInZoomControls(true);
        // 去掉那个丑出翔的缩放按钮，只保留双指缩放
        webSettings.setDisplayZoomControls(false);
        // 设置加载进来的页面自适应手机屏幕
        webSettings.setUseWideViewPort(true);
        // 让缩放显示的最小值为起始
        //webview.setInitialScale((int) PhoneUtil.getDisplay() * 100);
        webview.setWebViewClient(new WebViewClient());
        webview.loadUrl(url);
        webview.setVerticalScrollBarEnabled(false); // 设置竖直滚动条隐藏
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initV();

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


}
